<?php

namespace App\Admin\Service;

use App\Admin\Grid\NGrid;
use App\Models\InviteCertificationModel;
use Encore\Admin\Grid\Filter;

class InviteCertificationService extends BaseService
{
    public string $table = 'invite_certification';

    /**
     * grid
     * @return void
     */
    public function grid(): void
    {
        $this->grid = new NGrid(new InviteCertificationModel);
        $this->grid->model()->leftJoin('shop_user', 'invite_certification.user_id', 'shop_user.user_id')
            ->where('invite_certification.status', 0)->select([
                'invite_certification.*',
                'shop_user.user_mobile'
            ]);
        $this->filter();
        $this->gid();
    }

    /**
     * filter
     * @return void
     */
    public function filter(): void
    {
        $this->grid->filter(function (Filter $filter) {
            $filter->disableIdFilter();
            $filter->column(1 / 2, function (Filter $filter) {
                $filter->equal('id', 'ID');
                $filter->equal('user_mobile', $this->l['userMobile']);
            });
            $filter->column(1 / 2, function (Filter $filter) {
                $filter->like('store_name', $this->l['storeName']);
                $filter->equal('serial_number', $this->l['serialNumber']);
            });
        });
    }
}
